proc usermod {nick handle chan otbn1 otbn tcl host} {
  global botnick home bcast

  if {![matchattr $handle o|m $chan]} {
    putquick "NOTICE $nick :\0034ERROR - Permission Denied."
    return 0
  } elseif {$otbn1 == ""} {
    putquick "NOTICE $nick :\0034ERROR - Should Be - (/msg) $botnick usermod <#channel> <nick> <level>"
    return 0
  } elseif {$otbn == ""} {
    putquick "NOTICE $nick :\0034ERROR - You need to specify one of the following levels:\002 avoice   aop   op   ccadmin   cadmin   bop   bcadmin   root"
    return 0 
  } elseif {[string tolower $otbn1] == [string tolower $botnick]} {
    putquick "NOTICE $nick :\0034ERROR - You may not modify the access level of this bot!"
    return 0
  }

  if {[validuser $otbn1]} {
    set hand2 $otbn1
  } elseif {[onchan $otbn1 $chan]} {
    set hand2 [nick2hand $otbn1 $chan]
  } else {
    putquick "NOTICE $nick :\0034ERROR - $otbn1 does not have any access to this bot at all."
    return 0
  }


  if {[matchattr $hand2 D]} { 
    putquick "NOTICE $nick :\0034ERROR - Unable To Execute Command - $hand2's user account is disabled - Enable $hand2's user account first before trying again."

    if {$bcast == "1"} {
      putquick "PRIVMSG $home :\002$nick\002 ($host) tried to usermod \002$hand2\002 in $chan - a disabled user account."
    }  

    return 0
  }

  #convert $otbn to lowercase
  set otbn [string tolower $otbn]


  if {$otbn == "avoice"} {
    chattr $hand2 |+vf-aodknm $chan 

  } elseif {$otbn == "op"} {
    chattr $hand2 |+of-vadknm $chan

  } elseif {$otbn == "ccadmin"} {
    if {![matchattr $handle o|n $chan]} {
      putquick "NOTICE $nick :\0034ERROR - Permission Denied."
      return 0
    }

    chattr $hand2 |+mof-vadkn $chan
  } elseif {$otbn == "cadmin"} {
     if {![matchattr $handle o]} {
       putquick "NOTICE $nick :\0034ERROR - Permission Denied."
       return 0
     }

     chattr $hand2 |+fmno-vadk $chan
  } elseif {$otbn == "bop"} {
    if {![matchattr $handle m]} {
      putquick "NOTICE $nick :\0034ERROR - Permission Denied."
      return 0
    }

    chattr $hand2 +foxp-vtjdknm
  } elseif {$otbn == "bcadmin"} {
    if {![matchattr $handle n]} {
      putquick "NOTICE $nick :\0034ERROR - Permission Denied."
      return 0
    }

    chattr $hand2 +fmoxtp-vjdkn
  } elseif {$otbn == "root"} {
    if {![matchattr $handle n]} {
      putquick "NOTICE $nick :\0034ERROR - Permission Denied."  
      return 0
    }

    chattr $hand2 +fnmtoxjp-vdk
  } else {
	# $otbn is invalid if user winds up here
      # --------------------------------------
	# - Note: aop is not supported in this edition.
 
      putquick "NOTICE $nick :\0034ERROR - You specified an access level that is not yet supported - please specify one of the following levels instead:"
      putquick "NOTICE $nick :\0034\002 avoice   aop   op   ccadmin   cadmin   bop   bcadmin   root"
  }

  # okay, valid user modified validly, now save and do whatever 
  # -----------------------------------------------------------
  putquick "NOTICE $nick :\0033Sucessfully modified $otbn1 to '\00312$otbn\0033' on\0034 $chan"

  if {$bcast == "1"} {
    putquick "PRIVMSG $home :\002$nick\002 ($host) requested me to usermod \002$hand2\002 to a '$otbn' on $chan" 
  }

  putlog "!$nick ($host)! usermod $chan $hand2 $otbn1"


  save
}










